package com.happyfamily.springboot.crowdsourcingplatform.dao.weng;

import com.happyfamily.springboot.crowdsourcingplatform.dto.LogDto;
import com.happyfamily.springboot.crowdsourcingplatform.model.OperationLog;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LogDao
{
	@Select("select count(*) from operationLog")
	Long countAllLogs();

	@Select("select * from operationLog order by createTime desc limit #{startPosition},#{limit}")
	List<OperationLog> getAllLogsByPage(@Param("startPosition") Integer startPosition, @Param("limit") Integer limit);

	/**
	 * 通过lid删除日志
	 *
	 * @param id
	 * @return
	 */
	@Delete("delete from operationLog where id = #{id}")
	int deleteLog(Integer id);

	/**
	 * 通过lid查找对应log
	 *
	 * @param id
	 * @return
	 */
	@Select("select * from operationLog t where t.id = #{id}")
	LogDto getById(Integer id);

	/**
	 * 模糊查询获取个数
	 *
	 * @param logDescribe
	 * @return
	 */
	Long getLogByFuzzy(@Param("logDescribe") String logDescribe, String operationType, @Param("startTime") String startTime, @Param("endTime") String endTime);

	/**
	 * 模糊查询获取集合
	 *
	 * @param logDescribe
	 * @param startTime
	 * @param endTime
	 * @param startPosition
	 * @param limit
	 * @return
	 */
	List<OperationLog> getLogByFuzzyPage(@Param("logDescribe") String logDescribe, String operationType, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("startPosition") Integer startPosition, @Param("limit") Integer limit);

	@Insert("insert " + "into " + "operationLog " + "(createTime,logLevel,operationUnit,method,args,userId,logDescribe,operationType,runTime,returnValue) " + "values (#{createTime},#{logLevel},#{operationUnit},#{method},#{args},#{userId},#{logDescribe},#{operationType},#{runTime},#{returnValue})")
	int insert(OperationLog operationLog);
}
